const request = require('request');

function readGeneratedFile(url) {
	return new Promise((resolve, reject) => {
		request.get(url, (error, response, body) => {
			if (error) {
				throw error;
			} else {
				try {
					const mapObject = JSON.parse(body);
					resolve(mapObject);
				} catch (e) {
					reject(new Error(`JSON 解析错误,可能是不存在的文件: ${decodeURIComponent(url)}`));
				}
			}
		});
	});
}

module.exports = readGeneratedFile;
